package com.commentlib.utils;

import com.google.gson.Gson;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * gson工具类
 */
public class GsonUtils {

	/**
	 * @param json
	 * @param classOfT
	 * @return
	 */
	public static <T> T fromJson(String json, Class<T> classOfT) {
		Gson gson = new Gson();
		return gson.fromJson(json, classOfT);
	}

	/**
	 * @param json
	 * @return
	 */
	public static <T> ArrayList<T> fromJsonList(String json, Type type) {
		List<T> lists;
		ArrayList<T> list1 = new ArrayList<T>();
		Gson gson = new Gson();
		lists = gson.fromJson(json, type);
		for (int i = 0; i < lists.size(); i++) {
			list1.add(lists.get(i));
		}
		return list1;
	}
}
